NVM.SliderMajor = (function () {
    var __core = NOVEM.Core;
    var __base = NOVEM.Base;
    var __modules = NOVEM.Modules;

    return {
        init: function (selector) {
            if (__core.getSelector(selector, false, false).length < 1) {
                return true;
            }

            // __core.loadJS({
            //     file: "plugins/swiper.js",
            //     id: "nvm-swiper-js",
            //     jsFolder: true,
            // });

            __core.isFuncTrue(function () {
                return typeof Swiper !== "undefined";
            }).then(function (cond) {
                if (!cond) {
                    return false;
                }
                __core.initFunction({ class: 'has-plugin-major', event: 'pluginMajorReady' });

                selector = __core.getSelector(selector, false);
                if (selector.length < 1) {
                    return true;
                }

                // replaceChild()


                sliderMajor = __core.getSelector('.slider-major', false);

                if (sliderMajor.length < 1) {
                    return true;
                }

                sliderMajor.forEach(function (element) {
                    if (!element.dataset.headingTag || !element.dataset.headingText) {
                        return true
                    };

                    let xpaths = '//' + element.dataset.headingTag + '[text()=\"' + element.dataset.headingText + '\"]';

                    let headings = document.evaluate(
                        xpaths,
                        document.querySelector('#vsb_content'),
                        null,
                        XPathResult.ANY_TYPE,
                        null
                    );

                    let Heading = headings.iterateNext();

                    let parent = Heading.parentNode;

                    if (parent.lastChild == Heading) {
                        parent.appendChild(element);
                    } else {
                        parent.insertBefore(element, Heading.nextSibling);
                    }

                });

            })
        },
    };
})();